package com.jeecg.common;

import java.io.Serializable;
import java.util.ResourceBundle;

import javax.xml.bind.annotation.XmlRootElement;

/**
 * 异常代码。
 * 
 * @author Debenson
 * @since 0.1
 */
@XmlRootElement
public class ExceptionCode implements Serializable {
  private static final long serialVersionUID = 452472665402145715L;

  public static final ExceptionCode ok = new ExceptionCode(0, "操作成功");
  public static final ExceptionCode failed = new ExceptionCode(-1, "操作失败");

  /** 内部异常，代码<0 */
  public static final ExceptionCode versionConflict = new ExceptionCode(-2, "版本冲突");
  public static final ExceptionCode entityNotFound = new ExceptionCode(-3, "找不到指定的实体");
  public static final ExceptionCode invalidPrarameter = new ExceptionCode(-4, "参数非法");
  public static final ExceptionCode invalidDomain = new ExceptionCode(-5, "非法的域");
  public static final ExceptionCode functionNotSupport = new ExceptionCode(-6, "功能不支持");
  public static final ExceptionCode signAuthorizedFailed = new ExceptionCode(-7, "签名认证失败");
  public static final ExceptionCode unkonwn = new ExceptionCode(-999, "未知异常");

  /** 系统异常，代码1~100 */
  public static final ExceptionCode notLogin = new ExceptionCode(1, "您还没有登录");
  public static final ExceptionCode notAuthorized = new ExceptionCode(2, "认证失败");
  public static final ExceptionCode fileUploadFailed = new ExceptionCode(3, "文件上传失败");
  public static final ExceptionCode fileUploadTooLarge = new ExceptionCode(4, "上传文件内容长度超长");
  public static final ExceptionCode smsSendFailed = new ExceptionCode(5, "短信发送失败");
  public static final ExceptionCode alreadyUpestGrade = new ExceptionCode(6, "已经是最新版本");
  public static final ExceptionCode jpushConnectionFailed = new ExceptionCode(7, "极光推送连接失败");
  public static final ExceptionCode jpushRequestFailed = new ExceptionCode(8, "极光推送请求参数错误");
  public static final ExceptionCode printFailed = new ExceptionCode(9, "打印失败");
  public static final ExceptionCode validatePrintSignFailed = new ExceptionCode(10, "验证打印签名失败");
  public static final ExceptionCode invalidSmsCaptcha = new ExceptionCode(11, "短信验证码不正确");
  public static final ExceptionCode excludeSendTimeInOneMin = new ExceptionCode(12,
      "一分钟内只能发送一次短信，请稍候再试");

  /** 用户模块，代码101~200 */
  public static final ExceptionCode usernameAndPasswordNotMatched = new ExceptionCode(101,
      "用户名和密码不匹配");
  public static final ExceptionCode userIsLocked = new ExceptionCode(102, "用户已被锁定，请联系管理员解锁");
  public static final ExceptionCode userNotFound = new ExceptionCode(103, "未找到指定的用户");
  public static final ExceptionCode invalidLoginToken = new ExceptionCode(104, "非法的登录认证码");
  public static final ExceptionCode invalidSmsConfig = new ExceptionCode(105, "非法的短信服务配置，请联系管理员");
  public static final ExceptionCode vendorOfSmsNotSet = new ExceptionCode(106, "未配置短信服务商，请联系管理员");
  public static final ExceptionCode mobileAndOpenIdNotMatch = new ExceptionCode(107,
      "当前微信号绑定其它手机号，请换手机号再试");
  public static final ExceptionCode memberNotRegister = new ExceptionCode(108, "用户未注册");
  public static final ExceptionCode openIdHasRegister = new ExceptionCode(109, "微信号已经注册了");
  public static final ExceptionCode mobileExist = new ExceptionCode(110, "手机已经注册");
  public static final ExceptionCode accountCheckFailed = new ExceptionCode(111, "账户校验失败: {0}");
  public static final ExceptionCode notSubscribeOrAuthroize = new ExceptionCode(112,
      "您未关注本公众号或未授权");
  public static final ExceptionCode mobileNotRegister = new ExceptionCode(113, "手机号还没有注册");
  public static final ExceptionCode templateOfSmsNotSet = new ExceptionCode(114, "未配置“{0}”短信模板");

  /** 业务模块 */
  public static final ExceptionCode signinNotFound = new ExceptionCode(201, "未找到指定的签到记录");
  public static final ExceptionCode memberNotFound = new ExceptionCode(202, "会员不存在");
  public static final ExceptionCode mbrScoreUpdateFailed = new ExceptionCode(203, "积分更新失败");
  public static final ExceptionCode exchangeNotFound = new ExceptionCode(204, "未找到指定的积分兑换记录");
  public static final ExceptionCode ticketNotFound = new ExceptionCode(205, "未找到指定的小票记录");
  public static final ExceptionCode fileNotFound = new ExceptionCode(206, "文件不存在");
  public static final ExceptionCode uploadFileFailed = new ExceptionCode(207, "上传文件失败");
  public static final ExceptionCode mediaNotFound = new ExceptionCode(208, "素材不存在或已经被删除");
  public static final ExceptionCode signinAlready = new ExceptionCode(209, "已经签到，不能再次签到");
  public static final ExceptionCode scoreNotEnough = new ExceptionCode(210, "积分不足");
  public static final ExceptionCode qtyNotEnough = new ExceptionCode(211, "商品已经被其他人兑换，现在已经没有了");
  public static final ExceptionCode goodNotFound = new ExceptionCode(212, "商品没有找到");
  public static final ExceptionCode activityNotFound = new ExceptionCode(213, "活动不存在");
  public static final ExceptionCode likeItAlready = new ExceptionCode(214, "已经点赞，不能重复点赞");
  public static final ExceptionCode markItAlready = new ExceptionCode(215, "已经评分，不能重复评分");
  public static final ExceptionCode alreadySubscribe = new ExceptionCode(216, "已经收藏不能重复收藏");
  public static final ExceptionCode scoreHstNotFound = new ExceptionCode(217, "找不到积分流水");
  public static final ExceptionCode tagIsOffinne = new ExceptionCode(218, "标签“{0}”已经被禁用");
  public static final ExceptionCode paperNotFound = new ExceptionCode(219, "找不到指定的问卷");
  public static final ExceptionCode paperDetailNotFound = new ExceptionCode(220, "找不到指定的问卷项");
  public static final ExceptionCode alreadyCommit = new ExceptionCode(221, "已经提交不能重复提交");
  public static final ExceptionCode defaultBizNotConfig = new ExceptionCode(222, "没有配置默认业态");
  public static final ExceptionCode notHdMember = new ExceptionCode(223, "不是海鼎会员");
  public static final ExceptionCode activityExpired = new ExceptionCode(224, "活动已经过期");
  public static final ExceptionCode appointAlready = new ExceptionCode(225, "已经预约，请勿重复预约");
  public static final ExceptionCode notAppointActivity = new ExceptionCode(226, "您还没有预约活动: {0}");
  public static final ExceptionCode activityHasJoined = new ExceptionCode(227, "您已经参加了活动: {0}");
  public static final ExceptionCode appointmentNotFound = new ExceptionCode(228, "找不到指定的活动预约");
  public static final ExceptionCode paperAnswerNotFound = new ExceptionCode(229, "找不到指定的问卷答案");
  public static final ExceptionCode mallNotFound = new ExceptionCode(230, "没有找到购物中心，请联系系统管理员");
  public static final ExceptionCode goodsScoreCannotSmallThanZero = new ExceptionCode(231,
      "礼品积分不能少于0");
  public static final ExceptionCode memberGradeNotSupport = new ExceptionCode(232, "会员所处等级权限不支持");
  public static final ExceptionCode parkingException = new ExceptionCode(233,
      "停车场接口异常: 异常代码={0}, 异常信息={1}");
  public static final ExceptionCode parkingOrderNotFound = new ExceptionCode(234,
      "停车缴费单“{0}”不存在或已经被删除");
  public static final ExceptionCode parkingRuleNotFound = new ExceptionCode(235, "没有对应的停车优惠规则");
  public static final ExceptionCode orderHasNotWxpay = new ExceptionCode(236, "订单“{0}”没有微信支付");
  public static final ExceptionCode goodsisexpired = new ExceptionCode(236, "该商品未到兑换日期或者已经过期");

  /** 券模块 */
  public static final ExceptionCode couponActivityObsolete = new ExceptionCode(301, "该活动已作废");
  public static final ExceptionCode couponActivityUncomit = new ExceptionCode(302, "该活动未提交");
  public static final ExceptionCode couponActivityStart = new ExceptionCode(303, "未到活动开始时间");
  public static final ExceptionCode couponActivityEnd = new ExceptionCode(304, "已超过活动开始时间");
  public static final ExceptionCode couponActivityMemberGrade = new ExceptionCode(305, "会员等级不够");
  public static final ExceptionCode couponActivityMemberScore = new ExceptionCode(306, "会员积分不够");
  public static final ExceptionCode couponActivityGetNum = new ExceptionCode(307, "该券领取数量超过限制");
  public static final ExceptionCode couponUsedNumByMemberOutOfRange = new ExceptionCode(308,
      "超出该券活动的每人每天使用数量限制");
  public static final ExceptionCode couponUsedNumByBizOutOfRange = new ExceptionCode(309,
      "超出每笔交易的使用券数限制");
  public static final ExceptionCode couponActivityUseDate = new ExceptionCode(310, "该券已经过期");
  public static final ExceptionCode couponActivityTenant = new ExceptionCode(311, "该券不能在该商户中使用");
  public static final ExceptionCode couponActivityBusiness = new ExceptionCode(312, "该券不能在该业态中使用");
  public static final ExceptionCode couponBalanceNotEnough = new ExceptionCode(313, "券余额不足");
  public static final ExceptionCode couponCantUse = new ExceptionCode(314, "该券不能使用");
  public static final ExceptionCode couponTypeNotExist = new ExceptionCode(315, "该券类型不存在");
  public static final ExceptionCode couponActivityNotExist = new ExceptionCode(316, "该券活动不存在");
  public static final ExceptionCode couponActivityBalanceNotEnough = new ExceptionCode(317,
      "券数量不足");
  public static final ExceptionCode tenantNotExist = new ExceptionCode(318, "商户不存在");
  public static final ExceptionCode couponActivityCantSend = new ExceptionCode(319, "该券不能赠送");
  public static final ExceptionCode couponNotExist = new ExceptionCode(320, "券不存在");
  public static final ExceptionCode couponHasAssigned = new ExceptionCode(321, "券已经领用，不能再次领用");
  public static final ExceptionCode invalidCouponActivityState = new ExceptionCode(322,
      "券活动状态异常，请检查券活动状态");
  public static final ExceptionCode couponActivityCannotDist = new ExceptionCode(323,
      "券活动不能派送，请检查券促销单");
  public static final ExceptionCode couponActivityCannotConsume = new ExceptionCode(324,
      "券活动不能核销，请检查券促销单");
  public static final ExceptionCode userHasNotAuthToConsue = new ExceptionCode(325, "该用户没有权限进行核销");
  public static final ExceptionCode couponHasNotUseTime = new ExceptionCode(326, "该券未到使用期限");
  public static final ExceptionCode couponExpire = new ExceptionCode(327, "该券已经过期无法核销");

  /** 微信相关 */
  public static final ExceptionCode wxAccountNotSet = new ExceptionCode(401, "没有设置微信公众号，请联系管理员");
  public static final ExceptionCode templateMsgNotFound = new ExceptionCode(402, "找不到指定的模板消息");
  public static final ExceptionCode templateMsgConfigNotSet = new ExceptionCode(403,
      "没有配置消息模板, 分类={0}");
  public static final ExceptionCode userTagNotFound = new ExceptionCode(404, "找不到指定的用户标签");
  public static final ExceptionCode fansNotFound = new ExceptionCode(405, "找不到指定的用户");
  public static final ExceptionCode fansTagExists = new ExceptionCode(406, "标签{0}已存在");
  public static final ExceptionCode tagAndUserNotBelongToSameAccount = new ExceptionCode(407,
      "标签和用户不属于同一微信账户");
  public static final ExceptionCode wxMediaNotFound = new ExceptionCode(407, "找不到多媒体素材");
  public static final ExceptionCode receiveTextNotFound = new ExceptionCode(408, "找不到客服消息");
  public static final ExceptionCode msgTypeNotSupport = new ExceptionCode(409, "不支持的媒体类型: {0}");
  public static final ExceptionCode wxNewsTplNotFound = new ExceptionCode(410, "找不到图文素材");
  public static final ExceptionCode mediaNotSynced = new ExceptionCode(411, "素材尚未发布到微信");
  public static final ExceptionCode onlyAddOneTypeWelcome = new ExceptionCode(412,
      "每个公众帐号不同关注类别的欢迎语只能配置一个");
  public static final ExceptionCode keywordNotFound = new ExceptionCode(413, "找不到指定的关键字");
  public static final ExceptionCode accountNotFound = new ExceptionCode(414, "找不到指定的微信账户");
  public static final ExceptionCode requestNotSetAccountId = new ExceptionCode(415,
      "没有设置微信公众号账户，是不是没有url里添加wxpubid参数");

  private static ResourceBundle rb = null;

  public ExceptionCode() {
  }

  public ExceptionCode(int code, String message) {
    if (rb == null) {
      final String resource = ExceptionCode.class.getPackage().getName().replace("\\.", "/")
          + "/exceptions";
      rb = ResourceBundle.getBundle(resource);
    }
    if (rb.containsKey(String.valueOf(code))) {
      message = rb.getString(String.valueOf(code));
    }
    this.code = code;
    this.message = message;
  }

  protected String getResourcePath() {
    return ExceptionCode.class.getPackage().getName().replace("\\.", "/") + "/exceptions";
  }

  private int code;
  private String message;

  /** 异常代码 */
  public int getCode() {
    return code;
  }

  public void setCode(int code) {
    this.code = code;
  }

  /** 异常信息 */
  public String getMessage() {
    return message;
  }

  public void setMessage(String message) {
    this.message = message;
  }

}
